import { defineConfig, loadEnv } from "vite"
import vue from "@vitejs/plugin-vue"
import VueJsx from "@vitejs/plugin-vue-jsx"
import devtools from "vite-plugin-vue-devtools"
import UnoCSS from "unocss/vite"
import { resolve } from "path"

const pathResolve = (dir: string): any => {
    return resolve(__dirname, ".", dir)
}
const alias: Record<string, string> = {
    "@": pathResolve("src"),
}

export default defineConfig((mode) => {
    const env = loadEnv(mode.mode, process.cwd())
    return {
        plugins: [vue(), devtools(), VueJsx(), UnoCSS()],
        resolve: {
            alias,
        },
        server: {
            port: 8889,
            proxy: {
                "/api": {
                    target: env.VITE_API_URL,
                    changeOrigin: true,
                },
            },
        },
    }
})
